package com.yy.json;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class JsonConfig {

    private Map<Class, ObjectSerializer> mSerializerMap = new HashMap<>();

    private JsonConfig() {

    }

    public static JsonConfig getInstance() {
        return JsonConfigHolder.JSON_CONFIG;
    }

    private static class JsonConfigHolder {
        private static final JsonConfig JSON_CONFIG = new JsonConfig();
    }

    public ObjectSerializer getSerializer(Class<?> cls) {
        ObjectSerializer serializer = mSerializerMap.get(cls);
        if (serializer != null) {
            return serializer;
        }
        if (List.class.isAssignableFrom(cls)) {
            serializer = ListSerializer.instance;
        } else if (Map.class.isAssignableFrom(cls)) {

        } else if (cls.isArray()) {

        } else {
            serializer = new JavaBeanSerializer(cls);
        }
        mSerializerMap.put(cls, serializer);
        return serializer;
    }
}
